<template>
  <div class="content-box" :class="{ 'nobottom-btn': !showbtn }">
    <div class="box-title">
      <img :src="getPicAssetURL(images)" />
      <span>{{ title }}</span>
    </div>
    <div class="box-main">
      <ul v-if="showList">
        <li
          :class="['item-li', currentLi === index ? 'active' : '']"
          :key="index"
          v-for="(item, index) in dataList"
          @click="clickLi(item, index)"
        >
          <el-tooltip :content="item.title" placement="bottom" :disabled="item.title?.length < 12">
            <span class="text-col">{{ item.title }}</span>
          </el-tooltip>
          <span :class="[currentPosition === index ? 'activeicon' : 'positionIcon']">
            <el-icon @click.stop="handlePositionSec(item, index)">
              <Position />
            </el-icon>
          </span>
        </li>
      </ul>
      <slot v-else></slot>
    </div>
    <div class="box-btn" v-show="showbtn" @click="handleAdd(item, index)">
      <div class="btn-box">
        <span>{{ btnName }}</span>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, reactive, watch } from 'vue'
import { getPicAssetURL } from '@/utils/loadAssets'
const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  dataList: {
    type: Array,
    default: () => []
  },
  images: {
    type: String,
    default: ''
  },
  btnName: {
    type: String,
    default: ''
  },
  showbtn: {
    type: Boolean,
    default: true
  },
  showList: {
    type: Boolean,
    default: true
  }
})

const currentLi = ref(null)
const currentPosition = ref(null)
const state = reactive({})
const emit = defineEmits(['clickLi'], ['handleAdd'], ['handlePosition'])
const clickLi = (item, index) => {
  currentLi.value = index
  emit('clickLi', item)
}
const handlePositionSec = (item, index) => {
  currentPosition.value = index
  // clickLi(item, index)

  emit('handlePosition', item)
}
watch(
  () => {
    props.dataList
  },
  () => {
    if (props.dataList.length) clickLi(props.dataList[0], 0)
  },
  {
    deep: true,
    immediate: true
  }
)
const handleAdd = (item, index) => {
  emit('handleAdd', item)
}
function defineChecked() {
  // currentLi.value = 0
}
defineExpose({ clickLi, defineChecked })
</script>
<style lang="less" scoped>
.content-box {
  height: 320px;
  width: 250px;
  background-color: rgba(27, 50, 103, 0.8); /* 50% 透明度 */
  border: 1px solid #149bd5;
  .box-title {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #149bd5;
    height: 34px;
    box-sizing: border-box;
    // background: white;
    opacity: 0.8;
    img {
      position: absolute;
      left: 10px;
      width: 20px;
      height: 20px;
      margin-right: 5px;
    }
    span {
      // color: #0154db;
      color: white;
      font-size: 14px;
      font-weight: bold;
    }
  }
  .box-main {
    box-sizing: border-box;
    // background: rgba(255, 255, 255, 0.7);
    height: calc(100% - 64px);
    ul {
      height: 100%;
      overflow-y: auto;
      font-size: 14px;
      .item-li {
        display: flex;
        justify-content: space-between;
        padding-left: 10px;
        padding-right: 10px;
        align-items: center;
        height: 35px;
        cursor: pointer;
        span:nth-of-type(1) {
          max-width: 250px; //也可以设置最大宽度
          overflow: hidden; //溢出隐藏
          white-space: nowrap; // 强制一行显示
          text-overflow: ellipsis; // 显示。。。省略号
        }
        span {
          color: white;
        }
        .activeicon {
          color: #0154db;
        }
        .positionIcon {
          color: white;
          // color: red !important;
        }
      }
      .item-li.active {
        .text-col {
          color: #00d3e9;
        }
      }
    }
  }
  .box-btn {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 30px;
    font-size: 14px;
    background: rgba(22, 155, 213, 1);
    cursor: pointer;
    span {
      color: white;
    }
  }
}
.nobottom-btn {
  .box-main {
    height: calc(100% - 35px);
  }
}
</style>
